<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实时时间</title>
    <style>
        #times {
            border: 1px solid #d9d9d9;
            margin-left: auto;
            margin-right: auto;
            margin-bottom: 10px;
            border-radius: 5px;
            width: 480px;
            height: 30px;
            line-height: 30px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="times">实时时间</div>
    <script>
        // 获取当前时间
        setInterval(function () {
            var dObj = new Date();
            var year = dObj.getFullYear();
            var month = dObj.getMonth() + 1;
            var day = dObj.getDate();
            var hour = dObj.getHours();
            var minute = dObj.getMinutes();
            var seconds = dObj.getSeconds();
            var times = document.getElementById("times");
            times.innerHTML = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + seconds;
        }, 1000);
    </script>
</body>

</html>